﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

namespace PhoneApp.Utilities
{
    internal class LogTest
    {
        public static void run()
        {
            int Num = 10;
            Thread[] threadArray = new Thread[Num];
            for (int i = 0; i < Num; i++)
            {
                threadArray[i] = new Thread(Go);
                threadArray[i].Start(i.ToString());
            }
        }

        private static void Go(object name)
        {
            MyLogger log = MyLogger.Instance;
            for (int i = 0; i < 10; ++i)
            {
                string msg = string.Format("Tread[{0}]: msg {1}", name, i);
                Console.WriteLine(msg);
                log.Debug(msg);
                log.Info(msg);
                log.Fatal(msg);
                log.Error(msg);

                Thread.Sleep(1);
            }
        }

        static MyLogger log = MyLogger.Instance;

        public static string TestPerformance(int qsize, bool bg = false)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            log.AutoFlushInterval = 5;
            log.QueBufferSize = qsize;
            log.Debug("log started");

            if (bg)
                log.Background();

            int number = 1000;
            for (int i = 0; i < number; i++)
            {
                log.Info("info msg:" + i);
            }

            string msg = "elapsed time: " + sw.ElapsedMilliseconds + "ms";
            msg += " average: " + (float)sw.ElapsedMilliseconds / number + " ms/line";
            log.Info(msg);
            Console.WriteLine(msg);
            sw.Stop();

            return msg;
        }
    }
}